import React, { PureComponent } from 'react';
import { ListView, PullToRefresh, Tabs, WhiteSpace } from 'antd-mobile';
import { connect } from 'dva';
import List from './list';
import './index.less';
import { Entity } from '@/services/searchParam';

// @ts-ignore
@connect(({ showList, list, global }) => ({ ...showList, list, global }))
export default class DataList extends PureComponent {
  constructor(props: any) {
    super(props);
    // @ts-ignore
    this.props.dispatch({
      type: 'list/getList',
      // @ts-ignore
      payload: this.props.global.searchParams,
    });
  }

  render(): any {
    return (
      <div style={{ height: '100%', width: '100%' }}>
        <Tabs
          tabs={tabs}
          initialPage={0}
          onChange={(tab, index) => {
            // @ts-ignore
            this.props.dispatch({ type: 'list/resetSource' });
            if (index === 0) {
              // @ts-ignore
              this.props.global.searchParams.entity = '';
              // @ts-ignore
              this.props.dispatch({
                type: 'list/getList',
                // @ts-ignore
                payload: this.props.global.searchParams,
              });
            }
            if (index === 1) {
              // @ts-ignore
              this.props.global.searchParams.entity = Entity.CAR;
              // @ts-ignore
              this.props.dispatch({
                type: 'list/getList',
                // @ts-ignore
                payload: this.props.global.searchParams,
              });
            }
            if (index === 2) {
              // @ts-ignore
              this.props.global.searchParams.entity = Entity.PEOPLE;
              // @ts-ignore
              this.props.dispatch({
                type: 'list/getList',
                // @ts-ignore
                payload: this.props.global.searchParams,
              });
            }
          }}
        >
          <div className={'tabs-style'}>
            <List />
          </div>
          <div className={'tabs-style'}>
            <List />
          </div>
          <div className={'tabs-style'}>
            <List />
          </div>
        </Tabs>
        <WhiteSpace />
      </div>
    );
  }
}

const tabs = [{ title: '全部' }, { title: '车找人' }, { title: '人找车' }];
